-- InterfereDevice
-- Created by panyl Oct/25/2016
-- 电流干扰装置

-- 初始化
function initInterfereDevice(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 格子不可到达
            if not self.gridData:canHit() then
                alert(getLocStr("grid_unreachable"));
                return;
            end

            local function okFunc()
                local pos = self.gridData:getPos();
                DungeonActionM.go("do_building_bonus", pos);
            end
            self:openBuildingView(okFunc, nil, nil, nil, nil, nil, nil, nil,
                {["effectId"] = 1338, ["effectIdOffset"] = {65, 125, 1.1}});
        end
    end

    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);

    -- 电流光效
    local node = cc.Node:create();
    playEffect(node, 1338, 0, 50);
    self.interfereEffectNode = node;
    self:addChild(node);
end

